#include <iostream>
#include <string>
#include <fstream>
#include <unordered_map>

const std::string dictname = "./dict.txt";
const std::string sep = ":";

bool Split(std::string& line, std::string& part1, std::string& part2)
{
    size_t pos = line.find(sep);
    if(pos == std::string::npos)
        return false;
    part1 = line.substr(0, pos);
    part2 = line.substr(pos+1);
    return false;
}

class Init
{
public:
    Init()
    {
        std::ifstream in(dictname);
        if(!in.is_open())
        {
            perror("ifstream open fail\n");
            exit(1);
        }
        std::string line;
        while(std::getline(in, line))
        {
            std::string part1, part2;
            Split(line, part1, part2); 
            _dict.insert(std::make_pair(part1, part2));
        }

        in.close();
    }

    std::string translation(const std::string& key)
    {
        auto it = _dict.find(key);
        if(it == _dict.end())
        {
            std::cout << "未找到指定字符串" << std::endl;
            return "Unkonw";
        }
        return it->second;
    }

    void print()
    {
        for(auto e : _dict)
        {
            std::cout << e.first << ":" << e.second << std::endl; 
        }
    }

    ~Init()
    {}
private:
    std::unordered_map<std::string, std::string> _dict;
};